package com.liyao.storehouse.service.impl;

import com.liyao.storehouse.dao.loginDao;
import com.liyao.storehouse.pojo.users.loginUser;
import com.liyao.storehouse.service.loginService;
import com.liyao.storehouse.utils.SqlFilter;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @program: storehouse
 * @description:
 * @author: liu yan
 * @create: 2024-11-14 10:43
 */
@Service
public class loginServiceImpl implements loginService {

    @Resource
    loginDao dao;
    @Override
    public JSONObject Mlogin(HttpSession session, String username, String password, HttpServletRequest request) {
        JSONObject js=new JSONObject();
        String upass= SqlFilter.validation(password);
        loginUser user=dao.getUserMes(username,upass);
        if(user!=null){
            if(user.getState()==1){
                session.setAttribute("user_id",user.getId());
                session.setAttribute("username",user.getUsername());
                session.setAttribute("role_id",user.getRole());
                session.setAttribute("dept_id",user.getDept());
                js.put("code","suss");
            }else{
                js.put("code","500");
            }
        }else{
            js.put("code","error");
        }
        return js;
    }
}
